import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);

import Setting from '../page/Setting.vue';
import Errors from '../page/Errors.vue';
import SlowResources from '../page/SlowResources.vue';
import Ajax from '../page/Ajax.vue';
import Page from '../page/Page.vue';
import UserType from '../page/UserType.vue';
import Log from '../page/Log.vue';
const router = new VueRouter({
    // mode: 'history',
    /* scrollBehavior,*/
    routes: [
        { name: 'index', path: '/', meta: { auth: true } },
        { name: 'setting', path: '/setting', meta: { auth: true }, component: Setting },
        { name: 'errors', path: '/errors', meta: { auth: true }, component: Errors },
        { name: 'slowResources', path: '/slowResources', meta: { auth: true }, component: SlowResources },
        { name: 'ajax', path: '/ajax', meta: { auth: true }, component: Ajax },
        { name: 'page', path: '/page', meta: { auth: true }, component: Page },
        { name: 'userType', path: '/userType', meta: { auth: true }, component: UserType },
        { name: 'log', path: '/log', meta: { auth: true }, component: Log },
    ]
})
router.beforeEach((to, from, next) => {
    // console.log(to)
    // console.log(from)
    if (to.meta.auth) {
        if (!localStorage.getItem('token')) {
            // debugger;
            if (process.env.NODE_ENV != 'production') {
                location.href = 'http://127.0.0.1:3000#login/'+location.href;
            } else {
                location.href = '/account#login';
            }
            return false;
        }
    }
    next();
})
export default router;